<?php
class ModelCategory extends Model {
	public function getCategories($data = array()) {
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category ORDER BY cat_id");
			$category_data = $query->rows;	 
		return $category_data;
	}
    public function getCatName($cat_id)
    {
        $query = $this->db->query("SELECT cat_name FROM " . DB_PREFIX . "category where cat_id='$cat_id'");
        $cat_name = $query->row['cat_name'];
        return $cat_name;
    }
    
    public function insert($cat_name)
    {
        $query  = $this->db->query("INSERT INTO " . DB_PREFIX . "category SET  cat_name = '" . $this->db->escape($cat_name) ."', status=1 ");
        $cat_id = $this->db->getLastId();
        return $cat_id;
    }    
    
    public function update($data)
    {
        $query  = $this->db->query("UPDATE " . DB_PREFIX . "category SET  cat_name = '" . $this->db->escape($data['cat_name']) ."' where cat_id='" . $this->db->escape($data['cat_id']) ."'");
    }
    
    public function getTotalCategories() {
        $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "category WHERE status = '1'");

        return $query->row['total'];
    }
    
    public function check($cat_name) {
        $query = $this->db->query("SELECT COUNT(*) AS num FROM " . DB_PREFIX . "category WHERE cat_name = '" . $this->db->escape($data['cat_name']) ."'");
        if($query->row['num'])
        {
            return true;
        }
        return false;
    }
}
?>